
<template>
  <div class="app-container">
    <div>
      <el-form :inline="true" :model="dataForm" ref="dataFormRef" class="demo-form-inline">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="dataForm.name" placeholder="请输入姓名"></el-input>
        </el-form-item><el-form-item label="年龄" prop="age">
          <el-input v-model="dataForm.age" placeholder="请输入年龄"></el-input>
        </el-form-item><el-form-item label="地址" prop="address">
          <el-input v-model="dataForm.address" placeholder="请输入地址"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="序号" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
        <el-table-column prop="age" label="年龄"></el-table-column>
        <el-table-column prop="address" label="地址"></el-table-column>
        
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleDelete(scope.row)">编辑</el-button>
          <el-button type="text" size="small" @click="handleClick(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="paging.page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="paging.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="paging.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { basicRequest } from '@/api/basics'

export default {
  
  data() {
    return {
      list: [],
      paging: {
        total: 0,
        page: 1,
        limit: 10
      },
      dataForm: { 
        name: '',
        age: '',
        address: '',
      },
      listLoading: true,
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    onSubmit() {
      this.paging.page = 1
      this.getList()
    },
    resetForm() {
      this.$refs.dataFormRef.resetFields()
      this.onSubmit()
    },
    handleSizeChange(val) {
      this.paging.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.paging.page = val
      this.getList()
    },
    handleDelete(row) {
      this.$message('开发中...')
    },
    handleClick(row) {
      this.$confirm('是否确定删除该行?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          basicRequest({
            id: row.id
          }, {}, '/vue-admin-template/table/del', 'DELETE').then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getList()
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    }, 
    getList() {
      this.listLoading = true
      basicRequest({
        ...this.paging,
        ...this.dataForm
      }, {}, '/vue-admin-template/user/list', 'GET').then(response => {
        this.list = response.data.items
        this.paging.total = response.data.total
        this.listLoading = false
      })
    }
  }
}
</script>


<style lang="scss" scoped>
.pagination{
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}
</style>
